//用户模型
package member

import (
	"database/sql"
	"fmt"

	_ "github.com/go-sql-driver/mysql"
)

func main() {

}

//获取用户信息
func UserInfo() string {
	//连接数据库;数据库类型，用户:密码@/数据库名?数据库编码
	db, err := sql.Open("mysql", "jirenyou:jirenyou@tcp(192.168.1.180:3306)/master_slave?charset=utf8")
	checkErr(err)

	//获取一条用户信息资源
	rows, err := db.Query("SELECT id,group_id,account FROM test_user WHERE id = ?", 2)
	checkErr(err)
	var username string

	for rows.Next() {
		var id int
		var group_id int
		var account string
		//var passwd string
		//var status int

		//获取资源信息
		err := rows.Scan(&id, &group_id, &account)
		checkErr(err)

		fmt.Println(id, group_id, account)

		username = account
	}

	return username

}

//检测错误
func checkErr(err error) {
	if err != nil {
		panic(err)
	}
}
